const namespace = 'dataChartModel'
function* getState(select, namespace) {
    return yield select(state => state[namespace]);
}

function* searchPostData(select, namespace) {
    const currentState = yield* getState(select, namespace);

    const periodStr = currentState.yearMonth || '';
    const year = periodStr.substr(0, 4);
    const month = periodStr.substr(5);
    return {
        year,
        month: month ? String(parseInt(month, 10)) : month,
        ...currentState
    };
}

export default {
    namespace,
    state: {
        employeeNo: '',
        name: '',
        rankName: '',
        yearMonth: '',
        salaryRecheckDiagramTypListVOList: []
    },
    reducers: {
        setPeriod(state, action) {
            const { payload: period } = action;

            return {
                ...state,
                period
            };
        },
        setInitData(state, action) {
            return {
                ...state,
                ...action.payload
            };
        }
    },
    effects: {
        *initData(state, { put }) {
            yield put({
                type: 'setInitData',
                payload: state.payload
            });
        }
    }
};
